/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.herenit.beijing.poc.empi.converter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import org.jdesktop.beansbinding.Converter;
import java.sql.Timestamp;
import java.text.ParseException;
import org.openide.util.Exceptions;

/**
 *
 * @author Obama
 */
public class TimeToStringConverter extends Converter<Timestamp, String> {

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public String convertForward(Timestamp value) {
        return df.format(value);
    }

    @Override
    public Timestamp convertReverse(String value) {
        Timestamp date = null;
        try {
            date = new Timestamp(df.parse(value).getTime());
        } catch (ParseException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            return date;
        }
    }
}
